[EventTiming] Improve some of the flaky tests This CL improves crossiframe.html by waiting for the load event (so it knows the iframe is ready), and makes it faster by awaiting for both the main frame and iframe observers at the same time. It also improves the buffered-and-duration test by considering cases in which the first event does actually get buffered due to machine slowness. Bug: 1074048 Change-Id: Ieb356a4a4bbcfca8454e8a76334df70867b4f954 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2343487 Reviewed-by: Yoav Weiss <yoavweiss@chromium.org> Commit-Queue: Nicolás Peña Moreno <npm@chromium.org> Cr-Commit-Position: refs/heads/master@{#796517} 
diff --git a/event-timing/buffered-and-duration-threshold.html b/event-timing/buffered-and-duration-threshold.html index 66be766..dbc9d92 100644 --- a/event-timing/buffered-and-duration-threshold.html +++ b/event-timing/buffered-and-duration-threshold.html 
@@ -24,13 +24,17 @@  const afterFirstClick = performance.now();  new PerformanceObserver(t.step_func(list => {  const mouseDowns = list.getEntriesByName('mousedown'); - if (mouseDowns.length === 0) - return; - assert_equals(mouseDowns.length, 1, 'Should only observe 1 click!'); - assert_greater_than(mouseDowns[0].processingStart, afterFirstClick, - 'The entry should not be the first click!!'); - verifyClickEvent(mouseDowns[0], 'myDiv', false /* isFirst */, 16 /* minDuration*/); - resolve1(); + mouseDowns.forEach(entry => { + if (entry.processingStart < afterFirstClick) { + // It is possible that the first event gets a slow duration and hence gets buffered. + // In this case the minDuration must be at least 104, otherwise it shouldn't have been + // buffered. + verifyClickEvent(entry, 'myDiv', true /* isFirst */); + } else { + verifyClickEvent(mouseDowns[0], 'myDiv', false /* isFirst */, 16 /* minDuration*/); + resolve1(); + } + });  })).observe({type: 'event', durationThreshold: 16, buffered: true});  // This should be the only click observed since the other one would not be buffered.  await clickOnElementAndDelay('myDiv', 30); 
diff --git a/event-timing/crossiframe.html b/event-timing/crossiframe.html index dfbd289..147e144 100644 --- a/event-timing/crossiframe.html +++ b/event-timing/crossiframe.html 
@@ -43,13 +43,14 @@    assert_less_than(childFrameData.processingStart, childFrameData.clickDone,  "The entry's processing start should be before than the child frame's clickDone."); - assert_greater_than(childFrameData.startTime, childFrameData.clickTimeMin, - "The entry's start time should be later than the child frame's \ - clickTimeMin.");  }    promise_test(async t => {  assert_implements(window.PerformanceEventTiming, "Event Timing is not supported"); + // Wait for load event so we can interact with the iframe. + await new Promise(resolve => { + window.addEventListener('load', resolve); + });  clickTimeMin = performance.now();  let observedMouseDown = false;  const observerPromise = new Promise(resolve => { @@ -66,15 +67,17 @@  resolve();  })).observe({type: 'event'});  }); - await clickAndBlockMain('button'); - clickDone = performance.now(); - await observerPromise; + clickAndBlockMain('button').then(() => { + clickDone = performance.now(); + });  const childFrameEntriesPromise = new Promise(resolve => {  window.addEventListener("message", (event) => { - resolve(event.data); + t.step(() => { + validateChildFrameEntries(event.data); + }); + resolve();  }, false);  }); -  let iframe = document.getElementById('iframe');  const iframeX = document.getElementById('iframe').offsetLeft;  const iframeY = document.getElementById('iframe').offsetTop; @@ -84,10 +87,7 @@  .pointerDown()  .pointerUp()  actions.send(); - const childFrameData = await childFrameEntriesPromise; - t.step(() => { - validateChildFrameEntries(childFrameData); - }); + return Promise.all([observerPromise, childFrameEntriesPromise]);  }, "Event Timing: entries should only be observable by its own frame.");    </script> 
diff --git a/event-timing/resources/crossiframe-childframe.html b/event-timing/resources/crossiframe-childframe.html index 58294ae..6a8bc6b 100644 --- a/event-timing/resources/crossiframe-childframe.html +++ b/event-timing/resources/crossiframe-childframe.html 
@@ -5,7 +5,6 @@  <div style="width: 300px; height: 300px" id='iframe_div' onmousedown="mainThreadBusy(120)">  <script>  (async () => { - const clickTimeMin = performance.now();  const observerPromise = new Promise(resolve => {  new PerformanceObserver(entryList => {  const mouseDowns = entryList.getEntriesByName('mousedown'); @@ -31,7 +30,6 @@  "processingEnd": entry.processingEnd,  "duration": entry.duration,  // Other values - "clickTimeMin": clickTimeMin,  "clickDone" : clickDone,  "target": entry.target.id,  }, '*');